package com.taiji.dicom4cloud.common.core.model;

import com.taiji.dicom4cloud.common.core.constrant.CommonConstants;
import lombok.*;

import java.io.Serializable;

/**
 * 响应信息主体
 *
 * @param <T>
 * @author jiwei
 * @since 2019/02/19
 */
@Builder
@ToString

@AllArgsConstructor
public class CommonResponse<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    @Getter
    @Setter
    private int code;

    @Getter
    @Setter
    private String msg;


    @Getter
    @Setter
    private T data;

    public CommonResponse() {
        super();
        code = CommonConstants.SUCCESS;
        msg = "success";
    }

    public CommonResponse(T data) {
        super();
        this.data = data;
        code = CommonConstants.SUCCESS;
        msg = "success";
    }

    public CommonResponse(Integer code, String message, T data) {
        super();
        this.data = data;
        this.code = code;
        this.msg = message;
    }

    public CommonResponse(Integer code, T message) {
        super();
        this.data = null;
        this.code = code;
        this.msg = (String) message;
    }

    public CommonResponse(T data, String msg) {
        super();
        this.data = data;
        this.msg = msg;
        code = CommonConstants.SUCCESS;
    }

    public CommonResponse(Throwable e) {
        super();
        msg = "fail";
        this.msg = e.getMessage();
        this.code = CommonConstants.FAIL;
    }
}
